<?php

class Core_Backend_Component_Global_View_Area_Create extends Core_Backend_Share_View_Form {

    public function __construct(){
        parent::__construct();
        $this->setTemplatePath('edit');
    }

    protected function buildNavigation($navigation){
        $navigation->addLabel($this->__('global.title.area_create'));
        parent::buildNavigation($navigation);
    }

    protected function buildToolbar($toolbar){
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('global/area/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.apply'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'apply')."')");
        $group->addButton($this->__('share.button.save'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'save')."')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form){
    	$entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())->setId('domain_form')->addHiddenField('id', 'area[id]');
        $form->addTextboxField($this->__('share.label.code'), 'code', 'area[code]', TRUE)
             	->addRequiredRule();
        $form->addTextboxField($this->__('share.label.name'), 'name', "area[name]", TRUE)
             	->addRequiredRule();
        $form->addTextboxField($this->__('global.label.first_namespace'), 'first_namespace', "area[first_namespace]", TRUE)
             	->addRequiredRule();
        $form->addTextboxField($this->__('global.label.second_namespace'), 'second_namespace', "area[second_namespace]", TRUE)
             	->addRequiredRule();
        $form->addTextboxField($this->__('share.label.url'), 'url', "area[url]", TRUE)
             	->addRequiredRule();
        $form->addTextboxField($this->__('share.label.domain_name'), 'domain_name', "area[domain_name]");
        if(!is_null($entity)){
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }
}